import { BaseResponse, request } from '@/utils/request';
import { RequestEnum } from '@/enums/httpEnum';

export const sysPermissionApi = {
  sysPermissionList: '/sys/permission/list',
  sysPermissionListJson: '/sys/permission/listJson',
  sysPermissionTree: '/sys/permission/tree',
  sysPermissionAdd: '/sys/permission/add',
  sysPermissionUpdate: '/sys/permission/update',
  sysPermissionDetail: '/sys/permission/detail',
  deletePermission: '/sys/permission/delete',
};

export const getSysPermissionList = (params: { rusticId: number }) => {
  return request<BaseResponse<API.MenuListResult>>({
    url: sysPermissionApi.sysPermissionList,
    method: RequestEnum.GET,
    params,
  });
};

export const getSysPermissionTree = () => {
  return request<API.MenuListResult>(
    {
      url: sysPermissionApi.sysPermissionTree,
      method: RequestEnum.GET,
    },
    { isGetDataDirectly: true },
  );
};

export const createSysPermission = (data: API.MenuAddParams) => {
  return request({
    url: sysPermissionApi.sysPermissionAdd,
    method: RequestEnum.POST,
    data,
  });
};

export const updateSysPermission = (data: API.MenuUpdateParams) => {
  return request({
    url: sysPermissionApi.sysPermissionUpdate,
    method: RequestEnum.PUT,
    data,
  });
};

export const deletePermission = (params: { id: number }) => {
  return request({
    url: sysPermissionApi.deletePermission,
    method: RequestEnum.DELETE,
    params,
  });
};
